package com.cai;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Title: FilterMain
 * @Author RuoLi
 * @Package com.cai
 * @Date 2024/1/28 21:12
 * @description:
 */
public class MiddleMain {
    public static void main(String[] args) {
        Stream<Integer> stream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

//        Stream<Integer> integerStream = stream.filter(i -> i > 5);//过滤出大于5的数

//        Stream<Integer> integerStream1 = stream.map(i -> i + 2);//修改每个元素的值

//        Stream<Integer> integerStream = stream.distinct();//去重

//        Stream<Integer> integerStream = stream.sorted();//排序 顺序排序

//        Stream<Integer> integerStream = stream.limit(3);//限制流的大小 指定元素的个数

//        Stream<Integer> integerStream = stream.skip(3);//跳过前3个元素

        //映射
        List<String> list=Arrays.asList("1,2,3.5","78+8,87。4");
        Stream<String> stringStream = list.stream().flatMap(s -> Stream.of(s.split(",")));//把流中的每一个值都变成一个流 再把所有流合成一个流
        stringStream.forEach(System.out::print);//输出1 2 3.5 78+8 87。4

        //消费 peek方法主要用于调试，以便在元素流过管道中的某个点时查看它们
        stream.peek(System.out::println).collect(Collectors.toList());
    }
}
